package com.scm.biz.action;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.scm.biz.bean.ProofingPattern;
import com.scm.biz.service.ProofingPatternService;
import com.scm.core.bean.exp.UfdmException;
import com.scm.core.bean.resp.RespBean;
import com.scm.utils.UploadAndDownUtil;

/**
 * 打样订单的action类
 * 
 * @author Young
 * @Date 2016.11.22
 */
@Controller
@RequestMapping("/proofingpattern")
public class ProofingPatternAction {

	@Resource
	private ProofingPatternService proofingPatternService;

	@RequestMapping("/saveMaterial")
	@ResponseBody
	public RespBean<String> saveMaterial(Long proofingPatternId, Long proofingOrderId, String accessoryDetail) {
		RespBean<String> respBean = new RespBean<String>();
		proofingPatternService.saveMaterial(proofingPatternId, proofingOrderId, accessoryDetail);
		return respBean;
	}
	
	@RequestMapping("/saveSizeFile")
	@ResponseBody
	public RespBean<String> saveSizeFile(Long proofingPatternId, Long proofingOrderId, String detailDescription)
			throws UfdmException {

		proofingPatternService.saveSizeFile(proofingPatternId, detailDescription, proofingOrderId);
		RespBean<String> respBean = new RespBean<String>();
		return respBean;
	}

	@RequestMapping("/saveMakeStatus")
	@ResponseBody
	public RespBean<String> saveMakeStatus(Long proofingPatternId, Long proofingOrderId) {
		proofingPatternService.saveMakeStatus(proofingPatternId, proofingOrderId);
		RespBean<String> respBean = new RespBean<String>();
		return respBean;
	}

	@RequestMapping("/saveBidPrice")
	@ResponseBody
	public RespBean<String> saveBidPrice(Long proofingPatternId, String costPrice, String minSalePrice,
			String salePrice, Long proofingOrderId) {
		proofingPatternService.saveBidPrice(proofingPatternId, costPrice, minSalePrice, salePrice, proofingOrderId);
		RespBean<String> respBean = new RespBean<String>();
		return respBean;
	}

	/**
	 * 尺码表文件下载
	 * 
	 * @param filename
	 *            附件名
	 * @param res
	 * @throws UfdmException
	 */
	@RequestMapping("downSizeFile")
	public void downFile(Long businessFileId, HttpServletRequest req, HttpServletResponse res) throws UfdmException {
		ProofingPattern proofingPattern = proofingPatternService.selectById(businessFileId);
		if (proofingPattern.getPatternSizeFile() != null && !proofingPattern.getPatternSizeFile().isEmpty()
				&& proofingPattern.getPatternSizeFile().indexOf(".") != -1) {
			String fileType = proofingPattern.getPatternSizeFile()
					.substring(proofingPattern.getPatternSizeFile().indexOf("."));
			UploadAndDownUtil.downFile("样式尺寸表" + fileType, proofingPattern.getPatternSizeFile(), req, res);

		}
	}

}
